#include <iostream>
#include <vector>
#include <unordered_map>
#include <windows.h>
using namespace std;

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
       unordered_map<int,int> cnt;
       //nums[j]=target-nums[i];

       for(int j=0;j<nums.size();j++)
       {
        auto it=cnt.find(target-nums[j]);
        if(it!=cnt.end())
        {
            return {it->second,j};
        }
        cnt[nums[j]]=j;

       } 
       return {};
    }
};

void printResult(const vector<int>& result) {
    cout << "[";
    for (size_t i = 0; i < result.size(); ++i) {
        cout << result[i];
        if (i < result.size() - 1) {
            cout << ",";
        }
    }
    cout << "]";
}

int main() {
    // 设置控制台输出为UTF-8编码
    SetConsoleOutputCP(CP_UTF8);
    
    Solution s;
    
    // 测试用例1：标准情况
    vector<int> nums1 = {2, 7, 11, 15};
    cout << "测试用例1 - 标准情况：" << endl;
    cout << "输入：nums = [2,7,11,15], target = 9" << endl;
    cout << "输出：";
    printResult(s.twoSum(nums1, 9));
    cout << "\n预期：[0,1]" << endl << endl;
    
    // 测试用例2：包含负数
    vector<int> nums2 = {-1, -2, -3, -4, -5};
    cout << "测试用例2 - 包含负数：" << endl;
    cout << "输入：nums = [-1,-2,-3,-4,-5], target = -8" << endl;
    cout << "输出：";
    printResult(s.twoSum(nums2, -8));
    cout << "\n预期：[2,4]" << endl << endl;
    
    // 测试用例3：有重复元素
    vector<int> nums3 = {3, 3};
    cout << "测试用例3 - 重复元素：" << endl;
    cout << "输入：nums = [3,3], target = 6" << endl;
    cout << "输出：";
    printResult(s.twoSum(nums3, 6));
    cout << "\n预期：[0,1]" << endl << endl;
    
    // 测试用例4：较大数值
    vector<int> nums4 = {1000000000, 1000000000};
    cout << "测试用例4 - 大数值：" << endl;
    cout << "输入：nums = [1000000000,1000000000], target = 2000000000" << endl;
    cout << "输出：";
    printResult(s.twoSum(nums4, 2000000000));
    cout << "\n预期：[0,1]" << endl;

    return 0;
}

